package app;
/**
 * F21SF Assignment 1
 * Name class with name details
 * @author Freddy Wong
 */
public class Name {
	private String firstName, middleName, lastName;

	/**
	 * Create a name object that assume middle name is empty with following parameters
	 * @param firstName
	 * @param lastName
	 */
	public Name (String firstName, String lastName) {
		this.firstName=firstName;
		middleName="";
		this.lastName=lastName;
	}
	
	/**
	 * Create a name object that take in first, middle & last name with following parameters
	 * @param firstName
	 * @param middleName
	 * @param lastName
	 */
	
	public Name (String firstName, String middleName, String lastName) {
		this.firstName=firstName;
		this.middleName=middleName;
		this.lastName=lastName;
	}
	
	/**
	 * Create a name object that full name consisted of first, middle & last name with following parameters
	 * @param fullName
	 */
	public Name(String fullName) {
		int space1=fullName.indexOf(' ');
		firstName=fullName.substring(0, space1);
		int space2=fullName.lastIndexOf(' ');
		if(space1==space2) { 
			middleName = "";
		}
		else {
			middleName=fullName.substring(space1+1, space2);
		}
			lastName=fullName.substring(space2+1);
	}
	
	/**
	 * returns first name of the name
	 * @return firstName
	 */
	public String getFirstName() {
		return firstName;
	}
	
	/**
	 * return middle name of the name
	 * @return middleName
	 */
	public String getMiddleName() {
		return middleName;
	}
	
	/**
	 * return last name of the name
	 * @return lastName
	 */
	public String getLastName() {
		return lastName;
	}
	
	/**
	 * return full name of the name
	 * @return fullName
	 */
	public String getFullName() {
		String fullName = firstName +" ";
		if(!middleName.equals("")) {
			fullName += middleName +" ";
		}
		fullName +=lastName;
		return fullName;
	}
	
	/**
	 * return first initial of first, middle & last name of the name
	 * @return shortName
	 */
	public String getShortName() {
		String shortName = String.valueOf(firstName.charAt(0));
		if(!middleName.equals("")) {
			shortName += middleName.charAt(0);
		}
		shortName += lastName.charAt(0);
		return shortName;
		
	}
	
	/**
	 * set first name to the name
	 * @param fName
	 */
	public void setFirstName (String fName) {
		firstName = fName;
	}
	
	/**
	 * set middle name to the name
	 * @param mName
	 */
	public void setMiddlename (String mName) {
		middleName = mName;
	}
	
	/**
	 * set last name to the name
	 * @param lName
	 */
	public void setLastname (String lName) {
		lastName = lName;
	}
} // end of CLASS
